//
//  TLSBaseViewController.h
//  Travel_World
//
//  Created by lanou on 15/10/12.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "TLSBaseModel.h"

@implementation TLSBaseModel
+ (NSMutableArray *)baseModelByArr:(NSMutableArray *)arr{
    //创建一个数组,用来装model
    NSMutableArray *modelArr = [NSMutableArray array];
    //对数组进行遍历,里面的元素都是字典
    for (NSDictionary *dic in arr) {
//        @autoreleasepool {//能确定某对象能释放了就尽快释放掉节约内存
            //直接通过遍历构造器的方式创建对象
            id model = [[self class] baseModelWithDic:dic];
            //把对象添加到数组
            [modelArr addObject:model];
//        }
    }
    return modelArr;
}
#pragma mark 遍历构造器方法用来创建对象
+ (instancetype)baseModelWithDic:(NSDictionary *)dic{
    //采用多态的方式进行对象的创建
    id model = [[[self class] alloc] initWithDic:dic];
    return model;
}
#pragma mark 自定义初始化方法用来实现对model用KVC进行赋值
- (instancetype)initWithDic:(NSDictionary *)dic{
    self = [super init];
    if (self) {
        //用KVC的方式对成员变量进行赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
//此方法很重要
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    if ([key isEqualToString:@"id"]) {
        self.myid = value;
    }
}
+ (CGRect)rectWithStr:(NSString *)str fontOfSize:(CGFloat)fontSize rectWithSize:(CGSize)rectSize{
    NSDictionary *fontDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:fontSize],NSFontAttributeName, nil];
    CGRect costomRect = [str boundingRectWithSize:rectSize options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
    return costomRect;
}
@end
